# 指定Python版本和下载URL
$pythonVersion = "3.10.4"
$pythonInstallerUrl = "https://mirrors.huaweicloud.com/python/3.10.4/python-3.10.4.exe"
$installerPath = "$env:TEMP\python-$pythonVersion.exe"

# 下载Python安装程序
Write-Output "Downloading Python installer..."
Invoke-WebRequest -Uri $pythonInstallerUrl -OutFile $installerPath

# 安装Python
Write-Output "Installing Python..."
Start-Process -FilePath $installerPath -ArgumentList '/quiet InstallAllUsers=1 PrependPath=1' -Wait

# 添加Python到系统环境变量
Write-Output "Adding Python to system Path..."
$envPath = [System.Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::Machine)
$pythonPath = "$pythonInstallPath;$pythonInstallPath\Scripts"
$newPath = "$pythonPath;$envPath"
[System.Environment]::SetEnvironmentVariable("Path", $newPath, [System.EnvironmentVariableTarget]::Machine)

Write-Host "Python installation and configuration completed."